package deprecated;

import java.util.Map;

/**
 * @ProjectName:zqdk-mvcbase
 * @Description: 
 * @author: 周楠
 * @date 2017年3月6日 下午2:58:25
 */

public class ExceptionHandlerMapping {
	
	
	private Map<String, ExceptionHandler<? extends Exception>> handblermap;
	
	public Map<String, ExceptionHandler<? extends Exception>> getHandblermap() {
		return handblermap;
	}
	public void setHandlermap(
			Map<String, ExceptionHandler<? extends Exception>> handblermap) {
		this.handblermap = handblermap;
	}


	public ExceptionHandler<? extends Exception> getExceptionHandler(Exception exception){
		
		
	   Class<?> eclass=exception.getClass();
		
	   ExceptionHandler<? extends Exception> eh=recursiveGet(eclass);

	   if(eh==null)eh=new DefaultExceptionHandler();
	   
		return eh;
		
	}
	
	
	private ExceptionHandler<? extends Exception> recursiveGet(Class<?> eclass){
		
		ExceptionHandler<? extends Exception> eh=handblermap.get(eclass.getName());
		
		if(eh==null) {
			
			Class<?> sclazz= eclass.getSuperclass();
			
			if(sclazz!=null){
				recursiveGet(sclazz);
			}
			
		} 
		   
		    return eh;
	}
	
	

}
